<template>
	<view class="" :style="{'--themcolor':usethemestore.themecolor,'--themcolor2':usethemestore.themecolor2}"
		v-if="currdata">
		<view class="fixtop">
			<fixtitletopVue>
				<template #l>
					<view class="fix-l" @click="back">
						<view>
							<view class="iconfont icon-jiantou"></view>
						</view>
					</view>
				</template>
				<template #c>
					<view class="fix-c">
						提交订单
					</view>
				</template>
			</fixtitletopVue>
			<view class="songfs">
				<view class="" :class="{slecet:getawy==0}" @click="changeget(0)">外卖配送</view>
				<view class="" :class="{slecet:getawy==1}" @click="changeget(1)">到店自取</view>
			</view>
		</view>
		<view class="" :style="{height:`calc(${heights} + 90rpx)`}"></view>
		<view class="conbox">
			<view class="tz">
				<view class="iconfont icon-daochu1024-07"></view>
				支付后等待商家备餐，进行送餐
			</view>
			<view class="address" @click="goaddress" v-if="useaddress.curraddress">
				<view class="address-l-t">
					<view class="a-l-t-l">
						{{useaddress.curraddress.address_address}}{{useaddress.curraddress.address_name}}</view>
					<view class="iconfont icon-jiantou"></view>
				</view>
				<view class="address-l-b">{{useaddress.curraddress.username}}{{+useaddress.curraddress.sex?'女士':'先生'}}
					<text>{{useaddress.curraddress.phone}}</text> </view>
			</view>
			<view class="" v-else @click="goaddress"
				style="height: 100rpx;background-color: #fff;border-radius: 15rpx;padding: 20rpx;font-size: 25rpx;display: flex;align-items: center;justify-content: center;">
				去添加地址
			</view>
			<view class="order-card">
				<view class="tit">{{currdata.shoppername}}店</view>
				<view class="cardbox">
					<view class="cardbox-l">
						<image :src="'http://127.0.0.1:3006'+currdata.currentdata.img" mode="aspectFill"></image>
					</view>
					<view class="cardbox-r">
						<view class="card-name">
							<view class="name">{{currdata.currentdata.title}}</view>
							<view class="card-price">单价￥{{currdata.currentdata.price}}</view>
						</view>
						<view class="mr">{{currdata.kw}}</view>
						<view class="cardsum">x{{currdata.sum}}</view>
					</view>
				</view>
				<view class="sumpri">
					<view class="l">小计</view>
					<view class="r"> <text>￥</text> {{price}}</view>
				</view>
			</view>
			<view class="other">
				<view class="beizu" @click="s_otherpop">
					<view class="l">备注</view>
					<view class="r">
						<view class="therdata">
							{{othershowdata?othershowdata:"口味、偏好等要求 "}}
						</view>
						<view class="iconfont icon-jiantou"></view>
					</view>
				</view>
				<view class="beizu" @click="showzj_pop">
					<view class="l">餐具数量</view>
					<view class="r" v-if="!isbaoc">请选择餐具数量<view class="iconfont icon-jiantou"></view>
					</view>
					<view class="r" v-else style="color: #52acff;">已选择选择餐具数量<view class="iconfont icon-jiantou"></view>
					</view>
				</view>
			</view>
			<view class="fixbot">
				<view class="pri"> <text>￥</text>{{price}}</view>
				<view class="submirt" @click="s_order_zf">
					立即支付
				</view>
			</view>
		</view>
		<uni-popup ref="otherpop" type="bottom" border-radius="10px 10px 0 0">
			<view class="otherpopbox">
				<view class="otherbox-tit">
					<view class=""></view>
					<view class="">添加备注</view>
					<view class="r" @click="closeotherpop">x</view>
				</view>
				<view class="kjdata">
					<view class="" v-for="(i,index) in therdata" :key="index" @click="selcet_other_data(i)">{{i}}</view>
				</view>
				<textarea v-model="areadata" placeholder="请输入口味偏好或配送要求,为给您提供实惠的价格,无法额外加星哦~" />
				<view class="othersubmit" @click="s_other_ok">完成</view>
			</view>
		</uni-popup>
		<uni-popup ref="chanj_upop" type="bottom" border-radius="10px 10px 0 0">
			<view class="chanj_upopbox">
				<view class="chanj_upop-tit">
					<view class="chanj_upop-tit_t">
						<view class="l">
							<view class="iconfont icon-dizhi"></view>
							<view class="">信阳学院宿舍区-7号楼7-419</view>
						</view>
						<view class="r">x</view>
					</view>
					<view class="chanj_upop-tit_b">王志帅先生 <text>19836970087</text> </view>
				</view>
				<view class="cjbox">
					<view class="cjbox-tag">该订单地址是否需要餐具？</view>
					<view class="slece-cj">
						<view class="" :class="{selected:isneedcj}" @click="s_selectcj(true)">根据餐量提供</view>
						<view class="" :class="{selected:!isneedcj}" @click="s_selectcj(false)">无需餐具</view>
					</view>
					<view class="" v-if="isneedcj">
						<view class="cjbox-tag">选择餐具数量？</view>
						<view class="slece-cj">
							<view class="" :class="{selected:cjslect}" @click="s_cj(true)">商家按餐量提供</view>
							<view class="sumcj" :class="{selected:!cjslect}" @click="s_cj(false)">
								<view class="jian" @click="s_jian">-</view>
								<view class="sum">{{sumcj}}份</view>
								<view class="add" @click="s_add">+</view>
							</view>
						</view>
					</view>
				</view>
				<view class="btn" @click="s_baocuncj">保存</view>
			</view>
		</uni-popup>
	</view>

</template>

<script setup>
	import {
		computed,
		ref
	} from 'vue'
	import fixtitletopVue from '../../components/fixtitletop/fixtitletop.vue';
	import {
		getstatusheight,
		gettitleheight
	} from '@/util/getsysinfo.js'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import themestore from '@/store/theme.js'
	import userstore from '@/store/user.js'
	import address from '../../store/address';
	import {
		addorders
	} from '@/api/index.js'
	const useaddress = address()
	const useuserstore = userstore()
	const usethemestore = themestore()
	const heights = getstatusheight() + gettitleheight() + 'px'
	const getawy = ref(0)
	const otherpop = ref()
	const therdata = ["不吃辣", "少放辣", "多放辣", "不吃葱", "不吃香菜", "不要冰", "地址封闭管理请电话联系", "将商品挂家门口或放前台，传达室"]
	const areadata = ref('')
	const othershowdata = ref()
	const chanj_upop = ref()
	const isneedcj = ref(false)
	const cjslect = ref(true)
	const sumcj = ref(1)
	const isbaoc = ref(false)
	const currdata = ref()
	const price = computed(() => {
		return currdata.value.sum * currdata.value.currentdata.price
	})
	onLoad(e => {
		currdata.value = JSON.parse(e.data)
	})
	const showzj_pop = () => {
		chanj_upop.value.open()
	}
	const back = () => {
		uni.navigateBack()
	}
	const s_otherpop = () => {
		otherpop.value.open()
	}
	const changeget = e => {
		getawy.value = e
	}
	const goaddress = () => {
		uni.navigateTo({
			url: "/pages/address/address"
		})
	}
	const closeotherpop = () => {
		otherpop.value.close()
	}
	const selcet_other_data = e => {
		areadata.value = areadata.value.concat(e)
	}
	const s_other_ok = () => {
		othershowdata.value = areadata.value
		closeotherpop()
	}
	const s_selectcj = e => {
		isneedcj.value = e
	}
	const s_cj = e => {
		cjslect.value = e
	}
	const s_jian = () => {
		if (sumcj.value == 1) return
		sumcj.value--
	}
	const s_add = () => {
		sumcj.value++
	}
	const s_baocuncj = () => {
		isbaoc.value = true
		chanj_upop.value.close()
	}
	const s_order_zf = async () => {
		const orderdata = {
			userid: useuserstore.userinfo.id,
			productid: currdata.value.currentdata.id,
			kw: currdata.value.kw,
			sum: currdata.value.sum,
			allprice: currdata.value.currentdata.price * currdata.value.sum,
			address: JSON.stringify(useaddress.curraddress),
			issong: getawy.value,
			bz: areadata.value,
			canju: (!isneedcj.value) ? "不许要餐具" : !cjslect ? '商家按量提供' : sumcj.value + '份',
		}
		const rudata = await addorders(orderdata)
		if (rudata.code == 200) {
			uni.navigateTo({
				url: `/pages/zf-order/zf-order?data=${JSON.stringify({...rudata.data,shopername:currdata.value.shoppername})}`
			})
		} 
	}
</script>
`
<style lang="scss" scoped>
	.selected {
		border: 1rpx solid var(--themcolor) !important;
		color: var(--themcolor);
	}

	.chanj_upopbox {
		max-height: 50vh;
		background-color: #eee;
		border-radius: 30rpx 30rpx 0 0;
		overflow: hidden;
		padding: 0 20rpx;

		.btn {
			height: 80rpx;
			width: 100%;
			border-radius: 20rpx;
			background-color: var(--themcolor);
			color: #fff;
			font-weight: 700;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 30rpx;
			margin: 20rpx 0;
		}

		.cjbox {
			max-height: 600rpx;
			width: 100%;
			border-radius: 20rpx;
			background-color: #fff;
			padding: 0 20rpx 20rpx 20rpx;

			.cjbox-tag {
				height: 80rpx;
				line-height: 70rpx;
				font-size: 30rpx;
			}

			.slece-cj {
				font-size: 30rpx;
				color: #7b7b7b;
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin-bottom: 30rpx;

				.sumcj {
					display: flex;
					justify-content: space-between;
					padding: 0 20rpx;
					align-items: center;

					.add,
					.jian {
						font-size: 33rpx;
						color: #7b7b7b !important;
					}
				}

				>view {
					height: 85rpx;
					width: 40%;
					border-radius: 20rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					border: 1rpx solid #eee;
				}

			}
		}

		.chanj_upop-tit {
			height: 100rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			padding: 0 20rpx;
			gap: 5rpx;

			.chanj_upop-tit_t {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 10rpx;
				font-size: 25rpx;
				gap: 5rpx;

				.l {
					display: flex;
					align-items: center;
					gap: 5rpx;
				}

				.r {
					font-size: 30rpx
				}

				.iconfont {
					font-size: 22rpx;
					color: #7b7b7b;
				}
			}


			.chanj_upop-tit_b {
				font-size: 22rpx;
				color: #7b7b7b;
				padding-left: 36rpx;

				text {
					margin-left: 10rpx;
				}
			}
		}
	}

	.otherpopbox {
		height: 50vh;
		background-color: #fff;
		border-radius: 30rpx;
		padding: 0 20rpx;

		.otherbox-tit {
			height: 100rpx;
			font-size: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-weight: 700;
			color: #000;

			.r {
				color: #7b7b7b;
				font-size: 35rpx;
			}
		}

		.kjdata {
			display: flex;
			flex-wrap: wrap;
			gap: 20rpx;

			>view {
				padding: 15rpx 20rpx;
				border: 1rpx solid #eee;
				font-size: 22rpx;
				border-radius: 20rpx;
				color: #000;
			}
		}

		textarea {
			height: 200rpx;
			width: 100%;
			border-radius: 15rpx;
			background-color: #eee;
			font-size: 25rpx;
			margin-top: 40rpx;
			padding: 20rpx;
			line-height: 40rpx;
		}

		.othersubmit {
			height: 90rpx;
			width: 100%;
			border-radius: 20rpx;
			background-color: var(--themcolor);
			font-size: 30rpx;
			font-weight: 700;
			line-height: 90rpx;
			text-align: center;
			color: #fff;
			margin-top: 60rpx;
		}
	}

	.conbox {
		height: calc(100vh - v-bind(heights) - 90rpx);
		background-color: #eee;
		padding: 0 20rpx;

		.fixbot {
			margin-top: 500rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 20rpx;
			border-radius: 15rpx;
			height: 120rpx;

			.pri {
				font-size: 40rpx;
				color: var(--themcolor);
				font-weight: 700;

				text {
					font-size: 25rpx;
				}
			}

			.submirt {
				height: 80rpx;
				width: 180rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 30rpx;
				background-color: var(--themcolor);
				font-size: 30rpx;
				color: #fff;
			}
		}

		.other {
			margin-top: 20rpx;
			background-color: #fff;
			border-radius: 15rpx;
			padding: 0 15rpx;

			>view {
				height: 70rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.l {
					font-size: 25rpx;
					font-weight: 700;
				}

				.r {
					font-size: 22rpx;
					color: #7b7b7b;
					display: flex;
					align-items: center;
					gap: 5rpx;

					.therdata {
						max-width: 500rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.iconfont {
						font-size: 17rpx;
						color: #7b7b7b;
						transform: rotate(180deg);
					}
				}
			}
		}

		.order-card {
			background-color: #fff;
			border-radius: 15rpx;
			padding: 0 15rpx;
			margin-top: 20rpx;

			.sumpri {
				height: 90rpx;
				border-top: 1rpx solid #eee;
				font-size: 33rpx;
				font-weight: 700;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.r {
					color: var(--themcolor);
				}

				text {
					font-size: 25rpx;
				}
			}

			.tit {
				height: 60rpx;
				display: flex;
				align-items: center;
				font-size: 22rpx;
				color: #7b7b7b;
			}

			.cardbox {
				height: 130rpx;
				display: flex;
				align-items: center;
				gap: 15rpx;

				.cardbox-l {
					width: 100rpx;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						height: 90rpx;
						width: 90rpx;
						border-radius: 15rpx;
					}
				}

				.cardbox-r {
					height: 100%;
					flex: 1;
					font-size: 22rpx;
					color: #7b7b7b;
					display: flex;
					flex-direction: column;
					justify-content: center;

					.card-name {
						font-size: 28rpx;
						font-weight: 700;
						color: #000;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.name {
							width: 350rpx;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}

						.card-price {}
					}

					.mr {}

					.cardsum {}
				}
			}
		}

		.address {
			height: 140rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			background-color: #fff;
			border-radius: 15rpx;
			padding: 15rpx;

			.address-l-t {
				font-size: 25rpx;
				font-weight: 700;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.iconfont {
					font-size: 20rpx;
					color: #7b7b7b;
					transform: rotate(180deg);
				}
			}

			.address-l-b {
				font-size: 25rpx;
				color: #7b7b7b;

				text {
					margin-left: 15rpx;
				}
			}
		}

		.tz {
			height: 50rpx;
			font-size: 22rpx;
			display: flex;
			align-items: center;
			gap: 10rpx;
			color: #7b7b7b;
			padding-left: 20rpx;

			.iconfont {
				font-size: 25rpx;
			}
		}
	}

	.fixtop {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background-color: #eee;
		padding: 0 20rpx;

		.songfs {
			height: 90rpx;
			width: 100%;
			border-radius: 40rpx 40rpx 0 0;
			background-color: #f5f5f5;
			display: flex;
			overflow: hidden;
			border: 1rpx solid #ececec;

			.slecet {
				background-color: #fff;
			}

			>view {
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
			}
		}

		.fix-l {
			height: 100%;
			width: 100%;
			display: flex;
			align-items: center;

			.iconfont {
				font-size: 25rpx;
			}
		}

		.fix-c {
			height: 100%;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 30rpx;
		}
	}
</style>